package com.mr.security.web.commons.validate.imagecode;

import com.mr.security.web.commons.validate.AbstractValidateCodeProcessor;
import com.mr.security.web.commons.validate.IValidateCodeProcessor;
import com.mr.security.web.commons.validate.entity.ImageCode;
import com.mr.security.web.commons.validate.entity.ValidateCode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;

/**
 * Class: ImageCodeProcessor
 * User (作者):MRui
 * TODO (描述)：图形验证码处理器
 * Date 2019-01-26 11:55
 */
@Component("imageIValidateCodeProcessor")
public class ImageCodeProcessor extends AbstractValidateCodeProcessor<ImageCode> {


    /**
    * User (作者): MRui
    * TODO (描述)：发送（通过流将图片输出到页面）
    * Data：2019-01-26 11:59
    */
    @Override
    protected void send(ServletWebRequest request, ImageCode validateCode) throws Exception {
        ImageIO.write(validateCode.getImage(), "JPEG", request.getResponse().getOutputStream());
    }
}
